﻿import request from '/@/utils/request';
enum Api {
  AddSysAppVersion = '/api/sysAppVersion/add',
  DeleteSysAppVersion = '/api/sysAppVersion/delete',
  UpdateSysAppVersion = '/api/sysAppVersion/update',
  SaveSysAppVersion = '/api/sysAppVersion/save',
  PageSysAppVersion = '/api/sysAppVersion/page',
  ExportSysAppVersion = 'api/sysAppVersion/export',
  UploadDownloadUrl = '/api/sysAppVersion/UploadDownloadUrl',
}

//导出App版本管理
export const exportSysAppVersionExcel=(params?:any)=>
	request({
		url:Api.ExportSysAppVersion,
		method:'post',
		data:params,
		responseType: 'blob'
	});

// 增加App版本管理
export const addSysAppVersion = (params?: any) =>
	request({
		url: Api.AddSysAppVersion,
		method: 'post',
		data: params,
	});

// 删除App版本管理
export const deleteSysAppVersion = (params?: any) => 
	request({
			url: Api.DeleteSysAppVersion,
			method: 'post',
			data: params,
		});

// 编辑App版本管理
export const updateSysAppVersion = (params?: any) => 
	request({
			url: Api.UpdateSysAppVersion,
			method: 'post',
			data: params,
		});

// 保存App版本管理
export const saveSysAppVersion = (params?: any) => 
	request({
			url: Api.SaveSysAppVersion,
			method: 'post',
			data: params,
		});

// 分页查询App版本管理
export const pageSysAppVersion = (params?: any) => 
	request({
			url: Api.PageSysAppVersion,
			method: 'post',
			data: params,
		});

	/**
	* 上传版本下载链接 
	*/
export const uploadDownloadUrl = (params: any) =>
		uploadFileHandle(params, Api.UploadDownloadUrl)

	export const uploadFileHandle = (params: any, url: string) => { 
	const formData = new window.FormData();
	formData.append('file', params.file);
	//自定义参数
	if (params.data) {
		Object.keys(params.data).forEach((key) => {
			const value = params.data![key];
			if (Array.isArray(value)) {
				value.forEach((item) => {
					formData.append(`${key}[]`, item);
				});
				return;
			}
			formData.append(key, params.data![key]);
		});
	}
	return request({
		url: url,
		method: 'POST',
		data: formData,
		headers: {
			'Content-type': 'multipart/form-data;charset=UTF-8',
			// ts-ignore
			ignoreCancelToken: true,
		},
	});
};
